<template>
	<div>
		<el-row>
			<el-col :span="24">
				<el-form :model="formData" ref="formDataRef" :rules="rules" label-width="100px">
					<el-form-item label="公司/部门:" prop="CompanyName">
						<el-input placeholder="请输入公司/部门" v-model="formData.CompanyName"></el-input>
					</el-form-item>
<!-- 					<el-form-item label="银行卡号:" prop="BankNumber">
						<el-input placeholder="请输入银行卡号" v-model="formData.BankNumber"></el-input>
					</el-form-item>
					<el-form-item label="卡额:" prop="InitPrice">
						<el-input placeholder="请输入银行卡余额" v-model.number="formData.InitPrice"></el-input>
					</el-form-item> -->
					<el-form-item label="银行卡号:" prop="BankId">
						<el-select v-model="formData.BankId" prop="BankId" style="width: 100%;" @change="BankIdChangeEvent" filterable>
							<el-option  v-for="item in selectData" :value="item.Id" :label="item.BankName +'-'+ item.BankNumber" v-show="!item.Delete"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="开户行:" v-if="BankName!=''">
						<!-- <el-input type="textarea" placeholder="请输入银行卡余额" v-model="BankName"></el-input> -->
						{{ BankName }}
					</el-form-item>
					<el-form-item align="right">
						<el-button type="primary" style="width: 100%;" @click="insertHandler">添加</el-button>
					</el-form-item>
				</el-form>
			</el-col>
		</el-row>
	</div>
</template>

<script>
	export default {
		props: {
			closeFun: {
				type: Function,
				required: true
			},
			isShow:{
				type: Boolean,
				required: true
			}
		},
		data() {
			return {
				formData: {
					CompanyName: "",
					BankId: "",
				},
				rules: {
					CompanyName: [{
						required: true,
						message: '请输入公司/部门',
						trigger: 'blur'
					}],
					BankId: [{
						required: true,
						message: '请选择银行卡',
						trigger: 'change'
					}],
				},
				selectData:[],
				BankName:'',
			}
		},
		watch:{
			isShow:{
				handler(value){
					if(value) this.getBankinfo()
				},
				immediate:true,
			}
		},
		methods: {
			insertHandler() {
				this.$refs.formDataRef.validate(valid => {
					if (valid) {
						this.$http.post('/api/Company/Insert/insert', {
							CompanyName: this.formData.CompanyName,
							BankId: this.formData.BankId
						}).then(res => {
							const {
								StatusCode,
								Data,
								Message
							} = res.data || 0
							if (StatusCode == 200) {
								this.$message.success('添加成功')
								this.resetFieldsEvent()
								this.$parent.$parent.dialogAddForm.show = false
								this.closeFun()
							} else {
								this.$message.warning(Message)
							}
						})
					}
				})
			},
			resetFieldsEvent(){
				this.$refs.formDataRef.resetFields()
				this.BankName = ''
			},
			getBankinfo() {
				this.$http.post('/api/Values/GetBankinfo' ).then(res => {
					const {
						StatusCode,
						Data
					} = res.data || 0
					if (StatusCode == 200) this.selectData = Data.Data
					else this.selectData = []
				})
			},
			BankIdChangeEvent(row){
				this.BankName = ''
				const bank = this.selectData.find(s=>s.Id == row)
				this.BankName += bank.BankName 
			}
		}
	}
</script>

<style>
</style>